package com.spring_book.spring_book.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component
public class TimeRecordAspect {
    @Around("execution(* com.spring_book.spring_book.controller.*.*(..))")
    public Object timeRecord(ProceedingJoinPoint pjt) throws Throwable {
        //记录开始时间
        long start = System.currentTimeMillis();
        //执行目标方法
        Object o = pjt.proceed();
        //记录结束时间
        long end = System.currentTimeMillis();
        log.info(pjt.getSignature()+"耗时"+(end-start)+"ms");
        return 0;

    }
}
